import java.util.Enumeration;
import java.util.Hashtable;

public final class ab
    implements bx
{

    private static final Object c = new Object();
    private static final Object d = new Object();
    private static final Object e = new Object();
    private static final Object f = new Object();
    private static final Object g = new Object();
    private static final Object h = new Object();
    private static final Object i = new Object();
    private int j;
    private aw k;
    public String a;
    private String l;
    private String m;
    public q b;
    private int n;
    private int o;
    private Hashtable p;
    private bs q;
    private bs r;
    private bs s;

    public static ab a(aw aw1, String s1)
    {
        cc cc1 = aw1.D;
        int i1 = 0;
        for(int j1 = cc1.a; i1 < j1; i1++)
        {
            ab ab1 = (ab)cc1.a(i1);
            if(s1.equals(ab1.a))
                return ab1;
        }

        return null;
    }

    public ab(aw aw1, String s1, String s2, q q1, int i1, bs bs1)
    {
        j = -1;
        p = new Hashtable();
        k = aw1;
        a = s1;
        l = s2;
        b = q1;
        n = i1;
        q = bs1;
        m = aq.a().a("queue", "") + ":" + a();
        aw1.D.e(this);
    }

    public final long a()
    {
        return (long)k.e;
    }

    public final void a(q q1)
    {
        b = q1;
        bq.a("channel/setinfo/" + a, q1, a(), h, this, false);
    }

    public final bp a(String s1)
    {
        return (bp)p.get(s1);
    }

    public final bp b()
    {
        return a(m);
    }

    public final cc c()
    {
        cc cc1 = new cc();
        for(Enumeration enumeration = p.elements(); enumeration.hasMoreElements(); cc1.e(enumeration.nextElement()));
        return cc1;
    }

    public final void d()
    {
        if(a == null)
        {
            bq.a("channel/alloc", q.c, a(), c, this, false);
            return;
        } else
        {
            q q1 = q.a(new q[] {
                q.c(l), b, q.c(n)
            });
            bq.a("channel/create/" + a, q1, a(), d, this, false);
            return;
        }
    }

    public final void e()
    {
        bq.a("channel/get/" + a, q.c, a(), g, this, false);
    }

    public final void a(q q1, int i1, bs bs1, bs bs2)
    {
        r = bs1;
        s = bs2;
        o = i1;
        b(q1);
    }

    public final void b(q q1)
    {
        q q2 = q.a(new q[] {
            q.a(a()), q1, q.c(o)
        });
        bq.a("channel/join/" + a, q2, a(), e, this, false);
    }

    public final void f()
    {
        bq.a("channel/leave/" + a, q.a(a()), a(), e, this, false);
    }

    public final void g()
    {
        k.D.d(this);
    }

    public final void a(String s1, q q1)
    {
        q q2 = q.a(new q[] {
            q.a(a()), q.c(s1), q1
        });
        bq.a("channel/broadcast/" + a, q2, a(), i, this, false);
    }

    public final void a(bp bp1, String s1, q q1, bs bs1)
    {
        q q2 = q.a(new q[] {
            q.a(a()), q.c(bp1.b), q.c(s1), q1
        });
        bq.a("channel/send/" + a, q2, a(), bs1, bs1 == null ? null : ((bx) (this)), false);
    }

    public final void c(q q1)
    {
        f(q1);
    }

    public final void d(q q1)
    {
        f(q1);
    }

    public final void b(String s1)
    {
        bp bp1;
        if((bp1 = (bp)p.remove(s1)) != null)
            a(1, bp1);
    }

    public final void e(q q1)
    {
        b = q1;
        a(6);
    }

    public final void a(q q1, p p1) {
        bp bp1;
        bb bb1;
        if (s != null && (bp1 = a(q1.a(2).toString())) != null) {
            bb1 = bb.b();
            try {
                bb1.a(1, bp1);
                bb1.a(2, q1.a(4).toString());
                bb1.a(3, q1.a(5));
                bb1.a(s);
                q q2;
                if (!(q2 = q1.a(3)).i()) {
                    p1.c = (q) bb1.b(0);
                    p1.a = new ac(q2.a(0).toString(), q2.a(1).f());
                }
                bb1.c();
            } catch (Exception exception) {
                bb1.c();
            } finally {
                bb1.c();
            }
        }
    }

    private void f(q q1) {
        String s1;
        q q2;
        s1 = q1.a(0).toString();
        q2 = q1.a(1);
        bp bp1;
        if ((bp1 = a(s1)) == null) {
            bp1 = new bp(this, s1, q2);
            p.put(s1, bp1);
            a(0, bp1);
        } else {
            bp1.c = q2;
            a(2, bp1);
        }
    }

    private void g(q q1)
    {
        Hashtable hashtable = p;
        p = new Hashtable();
        int i1 = 0;
        for(int j1 = q1.b(); i1 < j1; i1++)
        {
            q q2;
            String s1 = (q2 = q1.a(i1)).a(0).toString();
            q q3 = q2.a(1);
            bp bp1;
            if((bp1 = (bp)hashtable.get(s1)) == null)
                bp1 = new bp(this, s1, q3);
            else
                bp1.c = q3;
            p.put(bp1.b, bp1);
        }

    }

    private void a(int i1) {
        bb bb1;
        if (i1 != j) {
            j = i1;
            if (q != null) {
                bb1 = bb.b();
                try {
                    bb1.a(1, i1);
                    bb1.a(2, this);
                    bb1.a(q);
                    bb1.c();
                } catch (Exception exception) {
                    bb1.c();
                } finally {
                    bb1.c();
                }
            }
        }
    }

    private void a(int i1, bp bp1) {
        bb bb1;
        if (r != null) {
            bb1 = bb.b();
            try {
                bb1.a(1, i1);
                bb1.a(2, bp1);
                bb1.a(r);
                bb1.c();
            } catch (Exception exception) {
                bb1.c();
            } finally {
                bb1.c();
            }
        }
    }

    public final void b(Object obj, p p1) {
        if ((obj instanceof bs)) {
            bb bb1 = bb.b();
            try {
                bb1.a(1, p1.c);
                bb1.a((bs) obj);
                bb1.c();
            } catch (Exception exception) {
                bb1.c();
            }
        } else {
            if (obj == i)
                return;
            if (obj == c) {
                a = p1.c.toString();
                d();
                return;
            }
            if (obj == d || obj == g) {
                q q1 = p1.c;
                l = q1.a(1).toString();
                b = q1.a(2);
                g(q1.a(3));
                a(0);
            } else if (obj == e) {
                g(p1.c);
                a(1);
            } else if (obj == f) {
                a(2);
            }
        }
    }

    public final void a(Object obj, p p1)
    {
        String s1 = p1.e;
        if("no.such.channel".equals(s1))
        {
            a(4);
            return;
        }
        if("conflicting.protocols".equals(s1))
        {
            a(5);
            return;
        }
        if("not.on.channel".equals(s1))
        {
            a(2);
        } else
        {
            "no.such.member".equals(s1);
        }
    }

}